package com.jyx.manage_media_process.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {
    public static final String EX_MEDIA_PROCESSTASK = "ex_media_processor";
    public static final String MEDIA_QUEUE = "queue-media-video-processor";
    public static final String MEDIA_ROUTINGKEY = "routingkey_media_video";

    @Value("${jyx-service-manage-media.mq.routingkey-media-video}")
    public String routingkey_media_video;

    //消费者并发数量
    public static final int DEFAULT_CONCURRENT = 10;

/*    @Bean("customContainerFactory")
    public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(DEFAULT_CONCURRENT);
        factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT);
        configurer.configure(factory, connectionFactory);
        return factory;
    }*/

    /**
     * 创建交换机
     * @return
     */
    @Bean(EX_MEDIA_PROCESSTASK)
    public Exchange EX_MEDIA_VIDEOTASK(){
        return ExchangeBuilder.directExchange(EX_MEDIA_PROCESSTASK).durable(true).build();
    }
    /**
     * 声明队列
     */
    @Bean(MEDIA_QUEUE)
    public Queue QUEUE_PROCESSTASK(){
        return new Queue(MEDIA_QUEUE,true);
    }

    @Bean
    public Binding binding_queue_media_processtask(@Qualifier(MEDIA_QUEUE) Queue queue ,
                                                   @Qualifier(EX_MEDIA_PROCESSTASK)Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MEDIA_ROUTINGKEY).noargs();
    }

}
